﻿using System;
using System.Collections.Generic;
using System.Text;
using Pixysoft.Framework.Reflection;
using Pixysoft.Weblications.Sango.Protocol.stage;
using Pixysoft.Weblications.Sango.Protocol;
using Pixysoft.Weblications.Sango.Dao;
using Pixysoft.Weblications.Sango.Constant;
using Pixysoft.Weblications.Sango.Protocol.player;
using Pixysoft.Weblications.Sango.Formular;

namespace Pixysoft.Weblications.Sango.Command.stage_rve
{
    partial class SangoStageRveHandler
    {
        public stagerve_submit stagerve_submit(string code)
        {
            string userCode = SangoManager.Authentication();
            stagerve_submit response = ReflectionManager.CreatePojo<stagerve_submit>();
            response.Succeed = false;

            Entities.Usr_Rvebattle rve = UsrRveBattleDao.GetRveBattle(code);
            if (rve.Battlestatus != GeneralStatusCollection.OPEN)
            {
                response.Message = "奖励已经领取";
                return response;
            }

            IEntityNoebeTransaction command = SettingHelper.EntityTransaction;
            command.Begin(delegate()
            {
                Entities.Usr_Profile profile = UsrProfileDao.getUsrProfile(userCode);
                UsrProfileDao.increaseSoulvalue(profile, rve.Soulvalue);
                command.Update(profile);

                if (rve.Equipmentserialcode != EquipmentFormular.default_equipment_none)
                {
                    EquipmentDao.tryDropUserEquipment(command, profile, rve.Equipmentserialcode);
                }

                rve.Battlestatus = GeneralStatusCollection.CLOSE;
                command.Update(rve);

                command.Commit();

                response.profile = UsrProfileFacade.ToProfile(profile);
            });

            response.rves = StageFacade.ToRveBattles(UsrRveBattleDao.GetRveBattles(userCode));
            response.Succeed = true;
            return response;
        }
    }

    public interface stagerve_submit : ISangoResponse
    {
        player_profile profile { get;set;}
        List<stage_rvebattle> rves { get;set;}
    }
}
